<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改联系记录')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-record-edit" th:object="${contactRecord}">
        <input name="recordId" th:field="*{recordId}" type="hidden">
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">联系人：</label>
                <div class="col-sm-8">
                    <span th:text="*{contactName}"></span>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">联系类型：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="contactType" name="contactType">
                        <option value=""></option>
                        <optgroup label="线下沟通">
                            <option value="见面">见面</option>
                            <option value="电话">电话</option>
                            <option value="会议">会议</option>
                        </optgroup>
                        <optgroup label="线上沟通">
                            <option value="微信聊天">微信聊天</option>
                            <option value="QQ聊天">QQ聊天</option>
                            <option value="邮件">邮件</option>
                            <option value="社交媒体">社交媒体</option>
                        </optgroup>
                        <optgroup label="视频会议">
                            <option value="腾讯会议">腾讯会议</option>
                            <option value="Zoom">Zoom</option>
                            <option value="Teams">Teams</option>
                        </optgroup>
                        <optgroup label="其他方式">
                            <option value="短信">短信</option>
                            <option value="邮件">邮件</option>
                            <option value="社交媒体">社交媒体</option>
                        </optgroup>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">联系内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{contactContent}">
                    <div class="summernote" id="contactContent"></div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">联系时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="contactTime" th:value="${#dates.format(contactRecord.contactTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">下次联系时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="nextContactTime" th:value="${#dates.format(contactRecord.nextContactTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">用户ID：</label>
                <div class="col-sm-8">
                    <input name="userId" th:field="*{userId}" class="form-control" type="text">
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: summernote-js" />
<script th:inline="javascript">
    var prefix = ctx + "contact/record";
    $("#form-record-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-record-edit').serialize());
        }
    }

    $("input[name='contactTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='nextContactTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function() {
        $('.summernote').each(function(i) {
            $('#' + this.id).summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                            data: data,
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            success: function(result) {
                                if (result.code == web_status.SUCCESS) {
                                    $('#' + obj.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function(error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
            var content = $("input[name='" + this.id + "']").val();
            $('#' + this.id).summernote('code', content);
        })
    });
</script>
</body>
</html>